/**
 * @Description 盘古平台部署接口文档
 * @Author zhangli
 * @Created 2023-07-05
 */
import express from 'express'
import bodyParser from 'body-parser'
const app = express()
// 配置静态资源
app.use(express.static('public'))

// post请求
app.use(bodyParser.json())
app.use(
  bodyParser.urlencoded({
    extended: true,
  })
)

// 拦截所有请求
app.all('*', function (req, res, next) {
  const host = req.headers.host || ''
  // 直接访问node接口设置可以跨域访问
  if (host.indexOf('127.0.0.1') === -1) {
    res.header('Access-Control-Allow-Credentials', true)
    res.header('Access-Control-Allow-Origin', req.headers.origin)
    res.header(
      'Access-Control-Allow-Headers',
      'Content-Type, token'
    )
    res.header('Access-Control-Allow-Methods', 'GET, PUT, DELETE, POST')
  }
  next()
})

app.get('/test', (req, res) => {
  res.send({
    code: 200,
  })
})

app.listen(8090, () => {
  console.log('server started at port 8090~~~')
})
